﻿using System.Web;
using System.Web.Mvc;
using Identity.Core;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;

namespace Identity
{
    [Authorize]
    public class IdentityController : Controller
    {
        private AppSignInManager _signInManager;
        private AppUserManager _userManager;

        public IdentityController()
        {
        }

        public IdentityController(AppUserManager userManager, AppSignInManager signInManager)
        {
            UserManager = userManager;
            SignInManager = signInManager;
        }

        protected AppSignInManager SignInManager
        {
            get
            {
                return _signInManager ?? HttpContext.GetOwinContext().Get<AppSignInManager>();
            }
            private set
            {
                _signInManager = value;
            }
        }

        protected AppUserManager UserManager
        {
            get
            {
                return _userManager ?? HttpContext.GetOwinContext().GetUserManager<AppUserManager>();
            }
            private set
            {
                _userManager = value;
            }
        }

        public IAuthenticationManager AuthenticationManager
        {
            get { return HttpContext.GetOwinContext().Authentication; }
        }
    }
}